package com.hngy.xpq.android_practice.user_main;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.hngy.xpq.android_practice.OrderActivity;
import com.hngy.xpq.android_practice.R;
import com.hngy.xpq.android_practice.database.SQLiteUser;
import com.hngy.xpq.android_practice.http.TcpClient;

public class SUserUpdateKey extends AppCompatActivity {

    EditText key1,key2;
    Button xg;
    SQLiteUser sqLiteUser;

    private void SUserUpdate() {
        key1 = findViewById(R.id.xg_xpq_key1);
        key2 = findViewById(R.id.xg_xpq_key2);
        xg = findViewById(R.id.button_xg);
    }

    public void IndexToast(String text){
        Toast.makeText(SUserUpdateKey.this,text,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_zhaohui_update_key2);
        SUserUpdate();
        sqLiteUser = new SQLiteUser(this);
        final Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        final String name = bundle.getString("name");
        xg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String information = "XG002//" + name + "//" + key1.getText().toString();
                String a = new TcpClient().Transits(information);
                if (TextUtils.isEmpty(key1.getText())){
                    IndexToast("密码不能为空!!");
                } else if (TextUtils.isEmpty(key2.getText())){
                    IndexToast("确认密码不能为空!!");
                } else if (!key1.getText().toString().equals(key2.getText().toString())){
                    IndexToast("两次密码不一致!!");
                } else if (a.equals("修改成功!")){
                    IndexToast("修改成功!!");
                    Intent intent1 = new Intent(SUserUpdateKey.this, OrderActivity.class);
                    startActivity(intent1);
                    finish();
                } else {
                    IndexToast("修改失败!!");
                }
            }
        });
    }

}